#ifndef UNITLISTMODEL_H
#define UNITLISTMODEL_H

#include <QAbstractItemModel>
#include <QStringList>
#include <QVector>

class UnitCollection;
class Unit;
class ColumnHeader;

struct UnitListModelItem {
    QString key;
    const Unit *unit;

    UnitListModelItem() : unit(NULL) { }
};

class UnitListModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    UnitListModel(const UnitCollection *_units, const ColumnHeader* _header, QObject *parent = 0);
    ~UnitListModel();

    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QModelIndex index(int row, int column,
                      const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &index) const;

    QString getUnitKey(int row);

signals:

public slots:
    void addUnit(const QString& key);

    void clearUnits();

private slots:
    void onColumnAboutToBeInserted();
    void onColumnInserted();
    void onColumnsAboutToBeCleared();
    void onColumnsCleared();

private:
    const ColumnHeader *header;
    const UnitCollection *units;
    QVector<UnitListModelItem*> rows;
};

#endif // UNITLISTMODEL_H
